package com.test.ch08;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ForList {
    public static void main(String[] args) {
        List<Integer> list=new ArrayList<>();
        list=Arrays.asList(1,2,3,4,5);
        Object[] arr=list.toArray();
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
        for(Integer i:list){
            System.out.print(i+" ");
        }
        System.out.println();
        Iterator it= list.iterator();
        while(it.hasNext()){
            Object v=it.next();
            System.out.print(v+" ");
        }
        System.out.println();
        list.forEach((i)->{
            System.out.print(i+" ");
        });
        System.out.println();
        list.forEach(System.out::print);
    }
}
